package com.zr.kufangkuqu.service.impl;

import com.zr.depotarea.pojo.Depotarea;
import com.zr.kufangkuqu.mapper.KuQuMapper;
import com.zr.kufangkuqu.pojo.DepotareadePotproperty;
import com.zr.kufangkuqu.pojo.KuQuSelectVo;
import com.zr.kufangkuqu.pojo.KuQuStatusVo;
import com.zr.kufangkuqu.service.KuQuService;
import com.zr.util.AllRecords;
import com.zr.util.ResultBuildVo;
import com.zr.util.ResultVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by star on 2019/7/16.
 */
@Service
public class KuQuServiceImpl implements KuQuService{
    @Autowired
    private KuQuMapper kuQuMapper;
    /**
     * 库房库区------分页
     * @param kuQuSelectVo
     * @return
     */
    @Override
    public ResultVo<AllRecords> queryPage(KuQuSelectVo kuQuSelectVo) {
        //查询数据
        List<DepotareadePotproperty> plantClassList = kuQuMapper.queryPage(kuQuSelectVo);
        //查询数量
        int count =  kuQuMapper.queryCount(kuQuSelectVo);
        //把当前页、每页大小、总页数、总条数、数据统一放入到AllRecords返回
        AllRecords allRecords = new AllRecords();
        allRecords.setPageIndex(kuQuSelectVo.getPageIndex());
        allRecords.setPageSize(kuQuSelectVo.getPageSize());
        allRecords.setTotalNumber(count);
        allRecords.resetTotalNumber(count);
        allRecords.setDataList(plantClassList);
        return ResultBuildVo.success(allRecords);
    }
    /**
     * 库房库区------查看
     * @param id
     * @return
     */
    @Override
    public ResultVo<KuQuSelectVo> queryKuQuById(Integer id) {
        if (id==null){
            return ResultBuildVo.error("查看时id不能为空！","500");
        }
        KuQuSelectVo kuQuSelectVo = kuQuMapper.queryById(id);
        if (kuQuSelectVo==null){
            return ResultBuildVo.error("查看对象不存在！","500");
        }
        return ResultBuildVo.success(kuQuSelectVo);
    }
    /**
     * 修改库房库区-----状态
     *
     */
    @Override
    public ResultVo updateStatus(KuQuStatusVo kuQuStatusVo) {
        Depotarea depotarea = new Depotarea();
        Date nowDate = new Date();
        depotarea.setUpdateTime(nowDate);
        depotarea.setUpdateName("小明");
        BeanUtils.copyProperties(kuQuStatusVo, depotarea);
        kuQuMapper.updateStatus(depotarea);
        return ResultBuildVo.success(kuQuStatusVo);
    }








}
